package servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import claseBean.*;

/**
 * Servlet implementation class Result
 */
@WebServlet("/Result")
public class Result extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public Result() {
		super();
		// TODO Auto-generated constructor stub
	}

	public void init() {

	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		ServletContext con = request.getServletContext();

		int termen1 = Integer.parseInt(request.getParameter("termen1"));
		int termen2 = Integer.parseInt(request.getParameter("termen2"));

		if (request.getParameter("adunare") != null) {
			int suma = termen1 + termen2;
			request.setAttribute("rezultat", suma);
			request.setAttribute("operatia", "adunarii");
			RequestDispatcher rd = con.getRequestDispatcher("/rezAdunare.jsp");
			rd.forward(request, response);
		} else if (request.getParameter("scadere") != null) {
			int diferenta = termen1 - termen2;
			request.setAttribute("rezultat", diferenta);
			request.setAttribute("operatia", "scaderii");
			RequestDispatcher rd = con.getRequestDispatcher("/rezAdunare.jsp");
			rd.forward(request, response);
		}

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

}
